
import pandas as pd

# 读取csv文件
def test1():
    df = pd.read_csv('159783.csv')
    print(df)

# 选择某一列：
def test2():
    data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}
    df = pd.DataFrame(data)
    print(df)
    column_a = df['A']
    print(column_a)

# 选择多列
def test3():
    data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}
    df = pd.DataFrame(data)
    columns_ab = df[['A', 'B']]
    print(columns_ab)

# 选择多行
def test4():
    data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}
    df = pd.DataFrame(data)
    rows_0_and_1 = df.loc[[0, 1]]
    print(rows_0_and_1)

# 选择某个元素
def test5():
    data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}
    df = pd.DataFrame(data)
    element_0_0 = df.loc[0, 'A']
    print(element_0_0)

# 修改某个元素
def test6():
    data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}
    df = pd.DataFrame(data)
    df.loc[0, 'A'] = 10
    print(df)

# 添加一列
def test7():
    data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}
    df = pd.DataFrame(data)
    df['D'] = [10, 11, 12]
    print(df)

# 删除一列
def test8():
    data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}
    df = pd.DataFrame(data)
    df.drop('B', axis=1, inplace=True)
    print(df)

# 删除一行
def test9():
    data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}
    df = pd.DataFrame(data)
    df.drop(1, axis=0, inplace=True)
    print(df)

# 排序
def test10():
    data = {'A': [3, 1, 2], 'B': [6, 4, 5], 'C': [9, 7, 8]}
    df = pd.DataFrame(data)
    df.sort_values(by='A', ascending=False, inplace=True)
    print(df)


test1()
test2()
test3()
test4()
test5()
test6()
test7()
test8()
test9()
test10()